package com.moeciyo.android.moeciyo.mvp.base;

import android.util.Log;

import com.moeciyo.android.moeciyo.fragment.HomeFragment;
import com.moeciyo.android.moeciyo.mvp.model.HomeCategoryModel;
import com.moeciyo.android.moeciyo.net.Api;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * describe：TODO
 * author：LiuQin
 * QQ：876771120
 * date：2017/10/25 23:05 modify by liujc
 */
public class PBasePager extends XPresent<BasePagerFragment> {

    protected static final int PAGE_SIZE = 10;

    public void loadData(String type, final int page) {
        Api.getGankService().getGankData(type, PAGE_SIZE, page)
                .compose(XApi.<HomeCategoryModel>getApiTransformer())
                .compose(XApi.<HomeCategoryModel>getScheduler())
                .compose(getV().<HomeCategoryModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<HomeCategoryModel>() {
                    @Override
                    protected void onFail(NetError error) {
                        getV().showError(error);
                    }
                    @Override
                    public void onNext(HomeCategoryModel gankResults) {
                        getV().showData(page, gankResults);
                    }
                });
    }
}
